/**
 * 
 */


var top_patient_panel = {
		xtype:'form',
		//width:740,
		height:90,
		region:'north',
		defaultType : 'textfield',
		//margins:'5 5 5 5',
		//layout:'table',
		//layoutConfig: {
    	//	columns: 3
		//},
		items:[
		       {
					fieldLabel : 'Bed',
					name : 'top_patient_bed',
					id:'top_patient_bed',
					allowBlank : true,
					readOnly:true
			   },
			   {
					fieldLabel : 'Patient_ID',
					name : 'top_patient_id',
					id:'top_patient_id',
					allowBlank : true,
					readOnly:true
			   },
		       {
				   	fieldLabel : 'Name',
				   	name : 'top_patient_name',
				   	id:'top_patient_name',
				   	allowBlank : true,
					readOnly:true
		       }
		       ]
}

var bl_tree_view_panel ={
		title:'Expr电子病历',
		xtype:'panel',
		items:{}
}

var new_drug_post = function(){
	var p = Ext.ComponentMgr.get('top_patient_id');
	//console.log(p.value);
	if(p.value == undefined){
		Ext.Msg.alert('Error','请先选择病人');
		return;
	}
	
	var drug_window = new Expr.ui.DrugPostWindow({
		title:'test',
		width:900,
		height:590,
		modal:true
	});
	
	drug_window.show();
	
	drug_window.initBlankWindowData(p.value);
}

var load_drug_post = function(report){
	var p = Ext.ComponentMgr.get('top_patient_id');
	//console.log(p.value);
	if(p.value == undefined){
		Ext.Msg.alert('Error','请先选择病人');
		return;
	}
	
	var drug_window = new Expr.ui.DrugPostWindow({
		title:'test',
		width:900,
		height:590,
		modal:true
	});
	
	drug_window.show();
	drug_window.loadData(report);
	//drug_window.initBlankWindowData(p.value);
	
	
}

var open_drug_post = function(report_id){
	var callback = function(response, e){
		if (true === e.status) {
			var report = response.data.report;
		}
	}
	Drug_Filter.drug_report_by_id(report_id,callback)
}


var right_on_patient_change = function(patient){
	
	var t = Ext.ComponentMgr.get('top_patient_bed');
	t.setValue(patient['bed']);
	var  t = Ext.ComponentMgr.get('top_patient_id');
	t.setValue(patient['id']);
	var t = Ext.ComponentMgr.get('top_patient_name');
	t.setValue(patient['name']);
	
	var drug_tree_direct_delegate = Drug_post_Tree.get_tree.createDelegate(Drug_post_Tree,[patient['id']],0);
	
	 var tree = new Ext.tree.TreePanel({
	        id:'drug_post_tree',
	        //width: 400,
	        //height: 400,
	        autoScroll: true,
	        root: {
	            id: 'root',
	            text: '药品不良反应上报'
	        },
	        loader: new Ext.tree.TreeLoader({
	    	    directFn:drug_tree_direct_delegate
	    	}),
	    	listeners:{
	    		click : function(node,e){
		    		var action = node.attributes.action;
		    		if (action != undefined){
		    			try{
		    				   //console.log(action);
		    			       eval(action);
		    			}
		    			catch(e){
		    			       Ext.Msg.alert('error','发生错误'+e);
		    			}
		    		}
		    	}
	    	}
	    	
	    });
	 
	 var t = Ext.ComponentMgr.get('panel_post');
	 t.removeAll();
	 t.add(tree);
	 t.doLayout();
	// tree.getRootNode().reload();
}



var post_view_panel ={
		title:'上报',
		//xtype:'panel',
		id:'panel_post',
		items: [
			       
		        ]

		       
}

var top_main_panel = {
		//width:740,
		height:90,
		region:'center',
		//margins:'5 5 5 5',
		layout:'accordion',
		//layoutConfig: {
    	//	columns: 3
		//},
		items:[bl_tree_view_panel,
		       post_view_panel
		       ]
}